package thread;
class Singleton{
    //类被加载时就初始化该静态成员 实例创建得的非常早  (饿汉)
    //一个类(进程) 中只能有唯一的实例
    private static Singleton instance = new Singleton();
    public static Singleton getInstance(){
        return instance;
    }
    private Singleton(){} //后续尝试new时便会编译报错
}
    public class Thread_Singleton{
        public static void main(String[] args) {
            //Singleton s = new Singleton();
            Singleton s = Singleton.getInstance();
            Singleton s2 = Singleton.getInstance();
            System.out.println( s == s2);//s和s2这两个对象实际上是一样的 输出true
        }
    }
